package com.kmproject.haifu.mvp.presenter;

import android.app.Application;

import com.jess.arms.integration.AppManager;
import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.mvp.BasePresenter;
import com.jess.arms.http.imageloader.ImageLoader;

import me.jessyan.rxerrorhandler.core.RxErrorHandler;
import me.jessyan.rxerrorhandler.handler.ErrorHandleSubscriber;

import javax.inject.Inject;

import com.kmproject.haifu.app.utils.AppUtil;
import com.kmproject.haifu.app.utils.RxUtils;
import com.kmproject.haifu.mvp.contract.MyStoreLookObtainedContract;
import com.kmproject.haifu.mvp.model.api.Api;
import com.kmproject.haifu.mvp.model.entity.ResultBean;
import com.kmproject.haifu.mvp.model.entity.beans.ObtainedHouseBean;
import com.kmproject.haifu.mvp.model.entity.resbean.HouseParmarBean;
import com.kmproject.haifu.mvp.model.entity.resbean.HouseRentRomeParmar;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 08/02/2019 14:07
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
@ActivityScope
public class MyStoreLookObtainedPresenter extends BasePresenter<MyStoreLookObtainedContract.Model, MyStoreLookObtainedContract.View> {
    @Inject
    RxErrorHandler mErrorHandler;
    @Inject
    Application mApplication;
    @Inject
    ImageLoader mImageLoader;
    @Inject
    AppManager mAppManager;

    @Inject
    public MyStoreLookObtainedPresenter(MyStoreLookObtainedContract.Model model, MyStoreLookObtainedContract.View rootView) {
        super(model, rootView);
    }


    /**
     * 删除房源
     * @param
     */
    public void  removeStore(String id) {

        mModel.removeStore(id).compose(RxUtils.applySchedulers(mRootView))
                .subscribe(new ErrorHandleSubscriber<ResultBean>(mErrorHandler) {
                    @Override
                    public void onNext(ResultBean resultBean) {
                      if (AppUtil.isSuccess(resultBean))
                      {
                          mRootView.removeStoreSuccess();
                      }else {
                         mRootView.showMessage(resultBean.getMessage());
                      }
                    }
                });
    }
    /*
  查询下架房源，用户的
  */
    public void listHouseRentShelvesForUser(String userId,HouseParmarBean houseParmarBean) {
        mModel.listHouseRentShelves(Api.APP_DOMAIN+"/app/listHouseRent/shelves/user/"+userId,AppUtil.entityToMap(houseParmarBean)).compose(RxUtils.applySchedulers(mRootView))
                .subscribe(new ErrorHandleSubscriber<ResultBean<List<ObtainedHouseBean>>>(mErrorHandler) {
                    @Override
                    public void onNext(ResultBean<List<ObtainedHouseBean>> listResultBean) {
                        if (AppUtil.isSuccess(listResultBean))
                        {
                            mRootView.listHouseRentShelvesSuccess(listResultBean);
                        }else {
                            mRootView.showMessage(listResultBean.getMessage());
                        }
                    }
                });
    }
    /*
     查询下架房源，店铺的
     */
   public void listHouseRentShelves(String storyId,HouseParmarBean houseParmarBean) {
     mModel.listHouseRentShelves(Api.APP_DOMAIN+"/app/listHouseRent/shelves/store/"+storyId,AppUtil.entityToMap(houseParmarBean)).compose(RxUtils.applySchedulers(mRootView))
             .subscribe(new ErrorHandleSubscriber<ResultBean<List<ObtainedHouseBean>>>(mErrorHandler) {
                 @Override
                  public void onNext(ResultBean<List<ObtainedHouseBean>> listResultBean) {
                    if (AppUtil.isSuccess(listResultBean))
                    {
                        mRootView.listHouseRentShelvesSuccess(listResultBean);
                    }else {
                        mRootView.showMessage(listResultBean.getMessage());
                    }
                 }
             });
   }
    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mErrorHandler = null;
        this.mAppManager = null;
        this.mImageLoader = null;
        this.mApplication = null;
    }
}
